<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<base href="<%=basePath%>">
		<meta charset="utf-8" />
		<%@ include file="../../share/layoutForm.jsp"%> 
	</head>
<body>
<form id="form1">
<div style="margin-top: 20px; margin-right: 30px;">
    <input id="parentId" type="hidden" />
    <input id="itemId" type="hidden" />
    <table class="form">
        <tr>
            <td class="formTitle">项目名<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="itemName" type="text" onblur="OverrideExistField(this.id,'<%=basePath%>sysDataItemDetail/isExist.do')" class="form-control" placeholder="请输入项目名" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">项目值<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="itemValue" type="text" onblur="OverrideExistField(this.id,'<%=basePath%>sysDataItemDetail/isExist.do')" class="form-control" placeholder="请输入项目值" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">排序<font face="宋体">*</font></th>
            <td class="formValue">
                <input id="sortCode" type="text" class="form-control" value="5" isvalid="yes" checkexpession="Num" />
            </td>
        </tr>
        <tr>
            <th class="formTitle" style="height: 37px;">选项</th>
            <td class="formValue">
                <div class="checkbox">
                    <label>
                        <input id="isEnabled" type="checkbox" checked="checked" />
                        有效
                    </label>
					<label>
                        <input id="isDefault" type="checkbox" />
                        默认
                    </label>
                </div>
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;">备注
            </th>
            <td class="formValue">
                <textarea id="otherMark" class="form-control" style="height: 70px;"></textarea>
            </td>
        </tr>
    </table>
</div>
</form>
<script>
    var keyValue = request('keyValue');
    var itemId = request('itemId');
    var parentId = request('parentId');
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "<%=basePath%>sysDataItemDetail/get.do",
                param: { keyValue: keyValue },
                success: function (data) {
                    if(data.type=="0"){
						$("#form1").SetWebControls(data.rows);
					}else{
						dialogAlert(data.message, -1);
					}
                }
            });
        } else {
            $("#parentId").val(parentId);
            $("#itemId").val(itemId);
        }
    }
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        if (postData["parentId"] == "") {
            postData["parentId"] = 0;
        }
        $.SaveForm({
            url: "<%=basePath%>sysDataItemDetail/edit.do?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        })
    }
    //验证：项目值、项目名 不能重复
    function OverrideExistField(id, url) {
        $.ExistField(id, url, { itemId: itemId });
    }
</script>
</body>
</html>